package org.blabla.SpringLettuceTest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;

/**
 * 代码一直报错：
 * Failed to instantiate LettuceConnectionFactory NoSuchMethodError: org.springframework.util.Assert.isTrue(ZLjava/util/function/Supplier;)V
 * 原因: 版本不兼容, idea生成spring工程时候有个lib文件夹存放了spring4.3的包
 */
@Component
public class RedisTest {
    @Autowired
    StringRedisTemplate stringRedisTemplate;

    public void redisTest(){
        ValueOperations valueOperations = stringRedisTemplate.opsForValue();
        valueOperations.set("springk1","springd1");
        System.out.println(valueOperations.get("springk1"));
    }

    public void redisClusterTest(){
        ValueOperations valueOperations = stringRedisTemplate.opsForValue();
        System.out.println(valueOperations.get("springck1"));
        valueOperations.set("springck1","springcd1v1");
        System.out.println(valueOperations.get("springck1"));
    }
}
